function PHatCalc= calculatePHat(w,X,wantedZ,R,C)
    PHatCalc=zeros(R,C);
    for ii=1:R % 9rows
        for jj=1:C
            if jj==1
                down=normcdf((X(ii,jj+1)-w.*wantedZ)./sqrt(1-w.^2),0,1);
                PHatCalc(ii,jj)=1-down;
            elseif jj==C
                up=normcdf((X(ii,jj)-w.*wantedZ)./sqrt(1-w.^2),0,1);
                PHatCalc(ii,jj)=up;
            else
                up=normcdf((X(ii,jj)-w.*wantedZ)./sqrt(1-w.^2),0,1);
                down=normcdf((X(ii,jj+1)-w.*wantedZ)./sqrt(1-w.^2),0,1);
                PHatCalc(ii,jj)=up-down;
            end
        end
    end
end

